export default {
  data() {
    return {
      mixinViewModuleOptions: {
        getDetailsURL: undefined, // 查询详情实体
        getDataListURL: undefined, // 数据列表接口，API地址
        deleteURL: undefined, // 删除接口，API地址
        tableKey: 'id', // 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...
        exportURL: undefined // 导出接口，API地址
      },
      list: [],
      pageNum: 1,
      pageSize: 10,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      // 遮罩层
      loading: true,
      // 是否显示弹出层
      open: false
    }
  },
  created() {

  },
  methods: {
    //开始查询列表的时候
    onStartQuery() {

    },
    getList() {
      const _this = this
      this.loading = true
      this.onStartQuery()
      this.queryParams.pageNum = this.pageNum
      this.queryParams.pageSize = this.pageSize
      this.mixinViewModuleOptions.getDataListURL(this.queryParams).then(response => {
        _this.list = response.rows
        _this.total = response.total
        _this.onLoadingListEnd()
      }).finally(() => {
        _this.loading = false
      })
    },
    //打开dislog
    onOpenHandleDialog() {

    },
    //编辑打开详情
    onHandleDetails(data, type) {

    },
    //重制查询
    onResetQuery() {

    },
    onLoadingListEnd() {

    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.addOrUpdate.init(this.$formType.add)
      this.onOpenHandleDialog()
      this.open = true
    },
    handleUpdate(row) {
      const _this = this
      const type = this.$formType.edit
      const queryId = row[this.mixinViewModuleOptions.tableKey] || this.ids
      this.mixinViewModuleOptions.getDetailsURL(queryId).then(response => {
        _this.$refs.addOrUpdate.init(type)
        _this.onHandleDetails(response, type)
        _this.onOpenHandleDialog()
        _this.open = true
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const _this = this
      const ids = row[this.mixinViewModuleOptions.tableKey] || this.ids
      this.$confirm('是否确认删除数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return _this.mixinViewModuleOptions.deleteURL(ids)
      }).then(() => {
        _this.getList()
        _this.msgSuccess('删除成功')
      }).catch(function() {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const _this = this
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return _this.mixinViewModuleOptions.exportURL(queryParams)
      }).then(response => {
        _this.download(response.msg)
      }).catch(function() {
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.onResetQuery()
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      const _this = this
      this.ids = selection.map(item =>
        item[_this.mixinViewModuleOptions.tableKey]
      )
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    showIndex(index) {
      return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
    }
  }
}
